package com.zyl.Ecs.device.web.controller;

import com.zyl.Ecs.common.domain.device.ext.RoomExt;
import com.zyl.Ecs.common.domain.device.vo.RoomVO;
import com.zyl.Ecs.common.response.Result;
import com.zyl.Ecs.common.response.ResultCode;
import com.zyl.Ecs.device.service.RoomService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.stream.Collectors;

/**
 * @version v1.0
 * @ProjectName: Ecs
 * @Package: com.zyl.Ecs.device.web.controller
 * @ClassName: RoomController
 * @Description TODO (房间控制器)
 * @Author 翟玉龙
 * @Date 2024/12/5-10:18
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/room")
public class RoomController {

    private final RoomService roomService;

    /**
     * 新增房间
     * @param roomVO 房间信息
     * @return {@link Result }<{@link ? }>
     */
    @PutMapping
    public Result<?> update(@RequestBody RoomVO roomVO) {
        roomService.update(RoomExt.toExt(roomVO));
        return Result.success();
    }

    /**
     * 查询房间列表
     * @return {@link Result }<{@link ? }>
     */
    @GetMapping
    public Result<?> list() {
        return Result.success(roomService.getList()
                .stream()
                .map(RoomVO::toVO)
                .collect(Collectors.toList()))
                .apply(ResultCode.SUCCESS.getMessage());
    }

}
